package com.ossean.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ossean.model.UpdateControlProjects;

public interface UpdateControlProjectsDao {
	
	//向更新表中添加数据
	@Insert("insert into ${table} (`id`,`update_time`) values (#{id},now())")
	public void insertOneItem(@Param("table") String table, @Param("id") int id);
	
	//检查更新表中是否有对相同项目的更新
	@Select("select * from ${table} where id=#{id}")
	public UpdateControlProjects findSameUpdate(@Param("table") String table, @Param("id") int id);
	
	//更新更新时间
	@Update("update ${table} set update_time=now() where id=#{model.id}")
	public void updateItem(@Param("table") String table, @Param("model") UpdateControlProjects model);
	

	//查找table中所有的记录(首先按照更新时间从近到远排，再按更新id从小到大排)
	@Select("select * from ${table} order by update_time desc, id asc")
	public List<UpdateControlProjects> findAllItems(@Param("table") String table);
	
	//删除对应id的记录
	@Delete("delete from ${table} where id=#{id}")
	public void deleteOneItem(@Param("table") String table, @Param("id") int id);

}
